<template>
  <div class="school">
    <h2>学校名称: {{ name }}</h2>
    <h2>学校地址: {{ address }}</h2>
    <button @click="sendSchoolMessage">点我传递学校信息</button>
    <p>要入学的学生信息: {{ studentMessage }}</p>
  </div>
</template>

<script>
export default {
  name: "student-name",
  data() {
    return {
      name: "千锋教育",
      address: "北京昌平",
      studentMessage: "",
    };
  },
  methods: {
    sendSchoolMessage() {
      this.$bus.$emit("getSchool-message", this.name, this.address);
    },
  },
  mounted() {
    this.$bus.$on("getStudent-message", (...val) => {
      this.studentMessage = val;
    });
  },
  beforeDestroy() {
    this.$bus.$off("getStudent-message");
  },
};
</script>

<style scoped>
.school {
  background-color: skyblue;
  padding: 10px;
  margin: 10px;
}
</style>
